﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HtmlAgilityPack;

namespace OlapProject
{
    class BaseParser : IParser
    {
        protected List<PropertyVO> container = null;
        protected WebLoader loader = new WebLoader();

        public List<PropertyVO> getData()
        {
            Log.writeLine(parseName + " STARTING ...");
            List<PropertyVO> result = new List<PropertyVO>();       
            parse(pageUrl, result);    
            return result;
        }

        private void parse(string url, List<PropertyVO> container)
        {
            this.container = container;
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();

            int counter = 0;    
 
            while (url != string.Empty)           
            {
                if (!loader.downloadHtmlDocument(url, document))
                    break;

                 parsePage(document);

                 Log.parserLog(++counter, parseName);
                if (counter >= DebugModel.MAX_PAGE_IN_DEBUG && DebugModel.debugMode)
                    break;                          

                url = getNextPageLink(document);
            }
            this.container = null;
         }

        virtual protected string getNextPageLink(HtmlDocument document)
        {
            return string.Empty;
        }

        virtual protected void parsePage(HtmlAgilityPack.HtmlDocument document)
        {
            throw new NotImplementedException();
        }


        public virtual string pageUrl 
        {
            get { throw new NotImplementedException(); } 
        }

        public virtual string parseName 
        {
            get { throw new NotImplementedException(); } 
        }
    }
}
